package com.sc.service.impl;

import com.sc.mapper.ExamSheetMapper;
import com.sc.pojo.ExamSheet;
import com.sc.service.ExamSheetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ExamSheetServiceImpl implements ExamSheetService {
    @Autowired
    ExamSheetMapper mapper;

    @Override
    public int addExamSheet(Integer userid, long examid, Integer[] titleids, String[] result,String[] userResult) {
        //得到分数集合
        Integer[] score = new Integer[result.length];
        for (int i = 0; i <result.length ; i++) {
            if(result[i].equalsIgnoreCase(userResult[i])) score[i] = 100/titleids.length;
            else score[i] = 0;
        }
        for (int i = 0; i <titleids.length ; i++) {
            mapper.insertSelective(new ExamSheet(null,userid,examid,titleids[i],userResult[i],score[i]));
        }
        return 1;
    }

    @Override
    public List<ExamSheet> show(Long examid, Integer userid) {

        return mapper.selectShowExam(userid,examid);
    }

    @Override
    public int deleteSheet(Integer id) {
        return mapper.deleteSheet(id);
    }

    @Override
    public int deleteExamSheet(Long id) {
        return mapper.deleteExamSheet(id);
    }

    @Override
    public int deleteClassExam(Long id) {
        return mapper.deleteClassExam(id);
    }
}
